#__*__coeding:utf-8__*__
#!/usr/share/python
'''
----------------------------------------------------------------
 文件功能描述： 常规文件处理
 author：罗卫
 时间：2017/08/18 18：20
--------------------------------------------------------------- 
'''

import os
from Base.tools import tools
import re


class IO:

    def __init__(self):
        self.flag=None
        self.file_path=None
        self.file_name=None
        self.charte=tools.charte()
        self.files_list=IO.listdir(self.flag)


    def file_path_str(self):
        """
        get full file path
        :return: file Complete path <type:str>
        """
        # try:

        path_str = '%s%s%s' % (self.file_path,self.charte,self.file_name)
        return path_str
        # except AttributeError:
        #     return 'Unknown file or unknown path.'


    @staticmethod
    def listdir(path):
        """
        Iterate over the path to obtain path under the name of a file or folder
        :param path: path is Configuration file configuration identification key
        :return: All files and directory name configuration directory file. <type: list>
        """
        try:
            filename_lists = os.listdir(path)
            return filename_lists
        except FileNotFoundError:
            return '请检查配置文件，配置路径是否正确'
    def read_file(self):
        """
        read file mothd
        :return: file line <type:str/dict>
        """
        with open(self.file_path_str(self))as lines:
            for lin in lines:
                if self.flag:
                    li = lin.find(self.flag)
                    if li == 0:
                        return lin
                else:
                    return lines

    def flag_compare(self):
        '''
        Compare the identifier corresponding directory name by return
        :return:directory_name <type:str>
        '''
        if self.flag:
            return 'conf'






